package com.tianjs.atomicTest;

import java.util.concurrent.atomic.AtomicReference;

public class AtomicReferenceTest {

	
	static AtomicReference<User> ai = new AtomicReference<User>();
	
	public static void main(String[] args) {
		User user = new User("jgq",15);
		ai.set(user);
		User updateUser = new User("jyt",17);
		ai.compareAndSet(user, updateUser);
		System.out.println(ai.get().getName());
		System.out.println(ai.get().getOld());
	}

	static class User{
		private String name;
		
		private int old;
		
		public User(String name, int old) {
			super();
			this.name = name;
			this.old = old;
		}

		public String getName() {
			return name;
		}

		public int getOld() {
			return old;
		}
		
	}
}
